import sortedcontainers
class Solution(object):
    def splitPainting(self, segments):
        d = sortedcontainers.SortedDict()
        for u, v, c in segments:
            d[u] = d.setdefault(u, 0) + c
            d[v] = d.setdefault(v, 0) - c
        k_list = list(d.keys())
        for i in range(1, len(k_list)):
            d[k_list[i]] += d[k_list[i - 1]]
        ans = []
        for i in range(len(k_list) - 1):
            if d[k_list[i]] > 0:
                ans.append([k_list[i], k_list[i + 1], d[k_list[i]]])
        return ans


